package cn.itcast.rnk.file.io;

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;

public class FileOperate {

	public static void main(String[] args) {

		test1();   //"D://my-md.css"
		
		test2();
		
	}

	private static void test2() {
		
		Charset charset = Charset.forName("US-ASCII");
		String s = "......";
		BufferedWriter writer = null;
		try {
		    writer = Files.newBufferedWriter(Paths.get("D://my-md.css"), charset);
		    writer.write(s, 0, s.length());
		} catch (IOException x) {
		    System.err.format("IOException: %s%n", x);
		} finally {
		    if (writer != null)
				try {
					writer.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
	}

	private static void test1() {
		
		Charset charset = Charset.forName("UTF-8");
		String s = "...";
		try (BufferedWriter writer = Files.newBufferedWriter(Paths.get("D://my-md.css"), charset)) {
		    writer.write(s, 0, s.length());
		} catch (IOException x) {
		    System.err.format("IOException: %s%n", x);
		}
	}

}
